module top();

wire [63:0] a,b;
wire Cin;
wire [63:0] S;
wire Cout;
reg [63:0] a_reg;
reg [63:0] b_reg;
reg Cin_reg;
integer seed;
reg [64:0] result;
integer i;

ling_adder_64 adder_1(.a(a),.b(b),.Cin(Cin),.S(S),.Cout(Cout));

assign a = a_reg;
assign b = b_reg;
assign Cin = Cin_reg;


initial
begin
// $monitor( "A=%x,  \nB=%x, \nCin=%x\n S=%x\n Cout=%x\n",a,b,Cin,S,Cout);
end 


initial
begin
    seed = 0;
    for(i = 0; i < 15; i = i+1)
    begin
	seed = seed + 1;
      	a_reg  =  $random(seed);
      	seed = seed + 1;
     	b_reg  =  $random(seed);
		Cin_reg =  $random(seed);
         #10; 
      	result = (a_reg + b_reg + Cin_reg);
		
	
	if(result[63:0] != S)
	begin
		$display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);		
		$display("Expected and Computed results dont match");
	end	
	else
	begin	
		$display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);		
		$display("Expected and Computed results match");
	end
			
  
      #10;
    end	//end for

      //Testing for some corner cases
	   $display("\nNow for some directed test cases:\n");	
	
	 #10; 
	 a_reg  =64'b0001;
	 b_reg  =64'b0001;
	 Cin_reg=1'b1;
	  #10; 
	    result = (a_reg + b_reg + Cin_reg);
	    $display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);		
		
	
	
	 #10;
	 a_reg  =64'b0001;
	 b_reg  =64'b0000;
	 Cin_reg=1'b0;
	  #10; 
	   result = (a_reg + b_reg + Cin_reg);
	    $display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);		
		
	
	 #10;
	 a_reg  =64'b0001;
	 b_reg  =64'b0000;
	 Cin_reg=1'b1;
	  #10; 
	result = (a_reg + b_reg + Cin_reg);
	    $display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);		
		

	 #10;
	 a_reg  =64'hFFFFFFFFFFFFFFFF;
	 b_reg  =64'b1;
	 Cin_reg=1'b0;
	  #10; 
	result = (a_reg + b_reg + Cin_reg);
	    $display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);		
		
		
	 #10;
	 a_reg  =64'h7FFFFFFFFFFFFFFF;
	 b_reg  =64'h7FFFFFFFFFFFFFFF;
	 Cin_reg=1'b0;
	  #10; 
	result = (a_reg + b_reg + Cin_reg);
	    $display("\na= %b\nb= %b\nCin = %b", a_reg, b_reg, Cin_reg);
		$display("Expected result = %b", result[63:0]);
		$display("Computed result = %b", S);
		$display("Expected Cout=%b",result[64]);
		$display("Computed Cout=%b",Cout);	
		

end

endmodule


